﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DMS.Data;
using DMS.Base;
using DMS.BaseClass;
using DMS.Business;
using DMS.Business.Modules.SystemManagement;
using DMS.Business.Utility;

namespace DMS.Web.Modules.SystemManagement
{
    public partial class EnumList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitControls();
                Search();
            }
        }

        private void InitControls()
        {
            List<SYS_EnumTypes> list = new EnumService().GetEnumTypes();
            ddlEnumType.DataSource = list;
            ddlEnumType.DataBind();
            ddlEnumType.Items.Insert(0, "全部");
        }

        private void Search()
        {
            int total;
            string enumTypeID= ddlEnumType.SelectedIndex > 0 ? ddlEnumType.SelectedValue : "";
            var list = new EnumService().GetEnums(enumTypeID, pager.CurrentPageIndex, pager.PageSize, out total);

            gvList.DataSource = list;
            gvList.DataBind();

            pager.RecordCount = total;
        }

        protected void gvList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                if (e.CommandName == "Deactive")
                {
                    new EnumService().Delete(e.CommandArgument.ToString());
                    Search();
                }
            }
            catch (Exception ex)
            {
                LogHelper.LogException(ex);
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            Search();
        }

        /// <summary>
        /// 翻页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void pager_PageChanged(object sender, EventArgs e)
        {
            Search();
        }
    }
}